package com.mark.springbootvideo.mapper;

import com.mark.springbootvideo.entity.Video;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author: MARK
 * @Date: 2019/9/8 10:29
 * @Version: 1.0.0
 * @Description: video数据访问层
 */
@Mapper
public interface VideoMapper {

    @Select("select * from video")
    List<Video> findAll();

    @Select("select * from video where id = #{id}")
    Video findById(Integer id);

    @Update("update video set title=#{title} where id = #{id}")
    void update(Video video);

    @Delete("delete from video where id = #{id}")
    void delete(Integer id);

    @Insert("INSERT INTO " +
                "`springboot_online_edu`.`video`" +
                "(`title`, `summary`, `cover_img`, `view_num`, `price`, `create_time`, `online`, `point`) " +
            "VALUES " +
                "(#{title}, #{summary}, #{coverImg}, #{viewNum}, #{price}, #{createTime}, #{online}, #{point});")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void save(Video video);
}
